package com.scwatch.core.service.impl;

import com.scwatch.common.orm.SearchFilter;
import com.scwatch.core.domain.Videolib;
import com.scwatch.core.repository.VideolibDao;
import com.scwatch.core.service.VideolibService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.Map;

/**
 * VideolibServiceImpl
 * 
 * @author gjl
 * 
 */
@Service
@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
public class VideolibServiceImpl implements VideolibService{
	public Page<Videolib> findAll(Map<String, String[]> params, Pageable pageable) {
		return videolibDao.findAll(spec(params), pageable);
	}


	private Specification<Videolib> spec(Map<String, String[]> params) {
		Collection<SearchFilter> filters = SearchFilter.parse(params).values();
		final Specification<Videolib> fsp = SearchFilter.spec(filters,Videolib.class);
		return fsp;
	}


	private VideolibDao videolibDao;

	@Autowired
	public void setVideolibDao(VideolibDao videolibDao) {
		this.videolibDao = videolibDao;
	}
}
